import { onBeforeRouteUpdate, useRoute } from "vue-router";
import { getTopCategoryAPI } from "@/api/category";

export function useCategory() {
    //实现面包屑效果
    const categoryData = ref({});
    const route = useRoute(); //vue3需要声明
    const getCategory = async (id) => {
        const res = await getTopCategoryAPI(id);
        categoryData.value = res.result;
        //vue2通过this.$router.params获得路由id
    };
    onMounted(() => getCategory(route.params.id));
    //轮播图逻辑

    onBeforeRouteUpdate((to) => {
        getCategory(to.params.id)
        //将要访问路由的id
    })
    return{
        categoryData
    }

}